import { defHttp } from '/@/utils/http/axios'
import {
    LoginParams,
    LoginResultModel,
    GetUserInfoByUserIdParams,
    GetUserInfoByUserIdModel,
} from './model/userModel'
import { ErrorMessageMode } from '/@/utils/http/axios/types'

enum Api {
    Login = '/auth/adminLogin',
    GetUserInfoById = '/getUserInfoById',
    GetPermCodeByUserId = '/getPermCodeByUserId',
}

/**
 * @description: 登录api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
    console.log('【提交】', params)
    return defHttp.request<LoginResultModel>(
        {
            url: Api.Login,
            method: 'POST',
            params,
        },
        {
            errorMessageMode: mode,
        }
    )
}

/**
 * @description: getUserInfoById
 */
export function getUserInfoById(params: GetUserInfoByUserIdParams) {
    return defHttp.request<GetUserInfoByUserIdModel>({
        url: Api.GetUserInfoById,
        method: 'GET',
        params,
    })
}

export function getPermCodeByUserId(params: GetUserInfoByUserIdParams) {
    return defHttp.request<string[]>({
        url: Api.GetPermCodeByUserId,
        method: 'GET',
        params,
    })
}
